[repo-assist] fix: correct string enum array serialisation in toQueryParams; add enum query-param tests#462
Merged
sergey-tihon merged 4 commits intoJun 21, 2026
Conversation
…um query-param tests
toQueryParams had a silent bug: any array of an int32-backed enum type (e.g. Status[])
matched the '| :? array<int32>' arm via CLR array variance before the generic Array arm
could run. For integer enums this happened to produce the right result (the integer
string), but for string enums (annotated with JsonStringEnumConverter) it discarded the
wire-name lookup and returned the underlying integer instead ('0' instead of 'active').
Fix: add a dedicated enum-array arm that fires before all the concrete array<T> arms.
It uses the cached buildEnumSerializer per element type so both integer and string enums
are serialised correctly.
Also simplifies createHttpRequestFromQueryLists by replacing the explicit ResizeArray
accumulation loop with Seq.concat, which lazily flattens without an intermediate heap
allocation (createHttpRequest already filters nulls in its own loop).
New tests in ToQueryParamsTests:
- single integer enum value
- single string enum value
- string enum value with special-character wire name (e.g. 'in-progress')
- integer enum array
- string enum array ← previously produced wrong integer strings
Test count: 512 → 517 (5 new). All 517 pass; 1 pre-existing skip unchanged.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes query-parameter serialization for enum arrays in the runtime helpers, and adds unit tests to cover both integer and string-enum query params (including arrays), plus a small change to query-param list flattening when building HTTP requests.
Changes:
- Update
toQueryParamsto correctly serialize enum arrays using the cached enum serializer (preserving string-enum wire names). - Add unit tests covering single enum values and enum arrays (integer + string enums, including special-character wire names).
- Simplify
createHttpRequestFromQueryListsby flattening viaSeq.concatand relying oncreateHttpRequestfor null filtering.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/SwaggerProvider.Tests/RuntimeHelpersTests.fs | Adds toQueryParams tests for enum query params (single values + arrays). |
| src/SwaggerProvider.Runtime/RuntimeHelpers.fs | Fixes enum-array handling in toQueryParams and simplifies query-param flattening for request creation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…60620-1841bb28be3b9fb0
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This PR was created by Repo Assist, an automated AI assistant.
Summary
This PR fixes a latent bug in
toQueryParamsand adds test coverage that surfaced it, plus a small performance improvement tocreateHttpRequestFromQueryLists.Bug fix: string enum arrays serialised as integers
Root cause
In .NET the CLR applies array variance for enum types: any array of an int32-backed enum (e.g.
Status[]) can be matched by a| :? int32[]pattern. IntoQueryParamsthe concrete| :? array<int32>arm therefore fired for every such enum array — before the genericArrayguard that was meant to handle enums.For integer enums this gave the right answer by accident (the integer string).
For string enums (annotated with
[<JsonConverter(typeof<JsonStringEnumConverter>)>]) it silently discarded the wire-name lookup and returned the underlying integer instead:Fix
Add a dedicated enum-array arm that fires before all the concrete
array<T>arms intoQueryParams:This uses the cached
buildEnumSerializerper element type, so both integer and string enums are serialised correctly. The existing| :? Arrayfallback for DateOnly/TimeOnly arrays is unchanged.Performance:
createHttpRequestFromQueryLists(Task 8)Replaced the explicit
ResizeArrayaccumulation loop withSeq.concat, which lazily flattens the nested sequences without an intermediate heap allocation.createHttpRequestalready filters nulls in its own loop, so the redundant null check was also removed.New tests (5)
All in
ToQueryParamsTests:toQueryParams→toParam→ integer serialisertoQueryParams→toParam→ wire-name serialiser"in-progress"round-tripTest Status
Schema_ParserTests.Fail to parse — no samples)Add this agentic workflows to your repo
To install this agentic workflow, run